package com.example.myapplication.shortvideo.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.databinding.ActivityVideoCommentBinding;
import com.example.myapplication.shortvideo.adapter.VideoCommentAdapter;
import com.example.myapplication.shortvideo.fragment.VideoCommentInputFragment;
import com.example.myapplication.shortvideo.utils.tikTok.ViewPagerLayoutManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: rongfeng
 * @date: 2020/6/17
 * @description
 */
public class VideoCommentActivity extends AppCompatActivity {

    private VideoCommentAdapter videoCommentAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ActivityVideoCommentBinding binding = DataBindingUtil.setContentView(
                this, R.layout.activity_video_comment);

        videoCommentAdapter = new VideoCommentAdapter(this);
        binding.recyclerView.setLayoutManager(new ViewPagerLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        binding.recyclerView.setAdapter(videoCommentAdapter);

        List<Object> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new Object());
        }
        videoCommentAdapter.addData(list);

        binding.imgClose.setOnClickListener(view -> {
            finish();
        });

        binding.tvInput.setOnClickListener(view -> {
            try {
                String tag = "VideoCommentInputFragment";
                FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                Fragment prev = getSupportFragmentManager().findFragmentByTag(tag);
                if (prev != null) {
                    ft.remove(prev);
                }
                ft.addToBackStack(null);
                ft.commit();
                getSupportFragmentManager().beginTransaction().add(VideoCommentInputFragment.getInstance(), tag).commitAllowingStateLoss();
            } catch (Exception e) {
            }
        });

        binding.viewBlank.setOnClickListener(view -> {
            finish();
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
